home *** CD-ROM | disk | FTP | other *** search
- DOS & DON'TS -- Part 12
- -----------------------
-
-
- Last issue we discussed the 1541
-
- Disk Drive's 'channels', particularly
-
- the Command/Error Channel (CEC), or
-
- Channel #15. This time we will dis-
-
- cuss how to actually use the 1541 as
-
- more than just a place to store prog-
-
- rams, but also as a place to put data
-
- to be used by your programs.
-
-
- A 'file' is a collection of data
-
- bytes grouped together and given a
-
- name, and stored on a mass-storage de-
-
- vice such as the 1541. These bytes
-
- may be anything that the computer can
-
- use and recognize. They may be the
-
- ASCII characters which make up text,
-
- or they may be other kinds of data.
-
- BASIC programs almost always use the
-
- ASCII means to represent data.
-
-
- A file is called a 'sequential'
-
- file if it can only be accessed from
-
- beginning to end. It is called a
-
- 'relative' file if it is divided into
-
- equally-sized 'records' that can be
-
- referenced in any order. A sequential
-
- file might be used to store text, such
-
- as a letter or report; or any other
-
- information which need not be accessed
-
- in a relative fashion, but can be used
-
- sequentially.
-
-
- For small amounts of data that must
-
- be accessed in a relative fashion such
-
- as a personal mailing list, it is pos-
-
- sible to use the data in memory in the
-
- form of one or more BASIC arrays, and
-
- to store the arrays sequentially in a
-
- sequential file when the program is
-
- done with them, so they can be read in
-
- next time.
-
-
- The important things to remember a-
-
- bout sequential files are that they
-
- must be accessed from beginning to end
-
- and that (at least when used from BA-
-
- SIC) they hold data in a form which
-
- can be used by the BASIC INPUT# state-
-
- ment. That means that each data item,
-
- meaning each peace of data that will
-
- go to a particular variable, must be
-
- separated from adjacent pieces of data
-
- in the file by a comma or a carriage
-
- return. For example, if you had a BA-
-
- SIC program that asked a question such
-
- as:
-
-
- 50 INPUT 'WHO ARE YOU AND HOW OLD
- ARE YOU? '; NA$, AGQ
-
-
- it would display:
-
-
- WHO ARE YOU AND HOW OLD ARE YOU
- ?
-
-
- and you could choose to answer either
-
- by separating your name and age with
-
- a comma, as in:
-
-
- WHO ARE YOU AND HOW OLD ARE YOU
- ? JOEL REA, 25
-
-
- or by pressing RETURN, as in:
-
-
- WHO ARE YOU AND HOW OLD ARE YOU
- ? JOEL REA
- ?? 25
-
-
- But if you didn't separate them, or
-
- tried to use another character as a
-
- separator, this would happen:
-
-
- WHO ARE YOU AND HOW OLD ARE YOU
- ? JOEL REA 25
- ??
-
-
- The program would assign 'JOEL REA 25'
-
- to NA$, and still need data for AG!
-
-
- As far as a BASIC program is con-
-
- cerned, a sequential file is merely
-
- stored INPUT. Thus, when writing to
-
- the file, you must write a separator
-
- between each piece of data. This sep-
-
- arator can be a comma or a carriage
-
- return (CHR$(13)). I recommend using
-
- the return by assigning it to the var-
-
- iable R$ near the beginning of your
-
- program:
-
-
- 10 R$=CHR$(13): REM CARRIAGE RE-
- TURN FOR DATA SEPARATOR IN FILE.
-
-
- Then you can use it easily when you
-
- need to write data:
-
-
- 160 PRINT#8, NA$; R$; AG
-
-
- A Return is automatically written af-
-
- ter the data in a PRINT# statement if
-
- no comma or semicolon appears at the
-
- end of the statement (just like PRINT-
-
- ing to the screen!).
-
-
- ======== continued in Part 13 ========
-